<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <!--显示红色-->
    <h2 v-color="color1">指令的值1测试</h2>
    <!--显示蓝色-->
    <h2 v-color="color2">指令的值2测试</h2>
    <button>
      改变第一个h1的颜色
    </button>
    <button>
      改变第二个h1的颜色
    </button>
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>
  <script>

    const app = new Vue({
      el: '#app',
      data: {
        color1: 'green',
        color2: 'blue'

      },
      computed: {

      },
      directives: {
        'color': {
          inserted (ele, obj) {
            ele.style.color = obj.value
          },

          // update (ele, obj) {
          //   ele.style.color = obj.value
          // }
        }
      }
    })
  </script>
</body>

</html>